import { UserProfilesAPI } from "@/request/api";
export default {
    namespaced: true,
    state: {
        userInfo: {
            // 头像
            headImg: require("../../assets/img/service.848ec511.png"),
            // 昵称
            nickName: "昵称",
            // 积分
            coin: 0
        },
        // 购物车数量
        cartTotal: 0
    },
    mutations: {
        // 修改登录状态
        changeUserInfo(state, payload) {
            state.userInfo = payload.userInfo;
            state.cartTotal = payload.cartTotal;
        },
        initUserInfo(state) {
            state.userInfo = {
                // 头像
                headImg: require("../../assets/img/service.848ec511.png"),
                // 昵称
                nickName: "昵称",
                // 积分
                coin: 0
            };
            state.cartTotal = 0;
        }
    },
    actions: {
        async asyncChangeUserInfo({ commit }, payload) {
            // 请求用户信息
            let res = await UserProfilesAPI();
            // 更新state数据
            commit("changeUserInfo", res.data)
        }
    }
}